pub trait Fly {
    fn fly(&self) {
        println!("fly~~~");
    }
}

pub struct CanFly;
impl Fly for CanFly {}

pub struct CanNotFly;
impl Fly for CanNotFly {
    fn fly(&self) {
        println!("can't fly~~~")
    }
}

pub struct Pig {
    fly_action: Box<dyn Fly>
}

impl Pig {
    pub fn new(fly: Box<dyn Fly>) -> Pig {
        Pig{fly_action: fly}
    }

    pub fn fly(&self) {
        self.fly_action.fly();
    }

    pub fn set_fly_action(&mut self, fly_action: Box<dyn Fly>) {
        self.fly_action = fly_action;
    }
}